<template>
  <div>
    <h1>展示用户</h1>
    <table>
        <tr>
            <td>用户编号</td>
            <td>用户名</td>
            <td>用户状态</td>
            <td>邮箱</td>
            <td>删除</td>
            <td>修改</td>
        </tr>
        <tr v-for="i in user_list">
            <td>{{i.id}}</td>
            <td>{{i.username}}</td>
            <td>{{i.user_status}}</td>
            <td>{{i.user_email}}</td>
            <td><a href="" @click.prevent="deleteuser(i.id)">删除</a></td>
            <td><a href="" @click.prevent="updateuser(i.id)">修改</a></td>
        </tr>
    </table>
  </div>
</template>

<script>
import axios from 'axios'
export default {

  data () {
    return {
        user_list:[]
    }
  },

  methods: {
      axios_get(){
           axios({
                url:'http://127.0.0.1:8000/app01/userapi/',
                method:'get'
            }).then(resp=>{
                console.log(resp)
                this.user_list=resp.data
            })

      },
      updateuser(uid){
          this.$router.push({name:'UpdateUser',params:{'uid':uid}})
      },
      deleteuser(uid){
           axios({
          url:'http://127.0.0.1:8000/app01/delete_user_view/'+uid+'/',
          method:'get'
      }).then(resp=>{
          console.log(resp)
          if(resp.data.code==200){
              this.axios_get()
          }
      })

      }

  },
  created(){
      this.axios_get()
      
  }
}
</script>